package com.mcc.app.group.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.mcc.app.group.domain.GroupClasses;
import com.mcc.app.group.service.IGroupClassesService;
import com.mcc.common.annotation.Log;
import com.mcc.common.core.controller.BaseController;
import com.mcc.common.core.domain.AjaxResult;
import com.mcc.common.core.page.TableDataInfo;
import com.mcc.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 班次
 *
 * @author gxy
 * @date 2021-07-08
 */
@Api(tags = "班次")
@RestController
@RequestMapping("/group/classes")
public class GroupClassesController extends BaseController {

    @Autowired
    private IGroupClassesService groupClassesService;

    @ApiOperation("查询班次列表")
    @ApiOperationSupport(order = 1)
    @GetMapping("/list")
    public AjaxResult<TableDataInfo<GroupClasses>> list(GroupClasses groupClasses) {
        List<GroupClasses> list = groupClassesService.selectGroupClassesList(groupClasses);
        return getDataTable(list);
    }

    @ApiOperation("查询班次列表(分页)")
    @ApiOperationSupport(order = 2)
    @GetMapping("/page")
    public AjaxResult<TableDataInfo<GroupClasses>> page(GroupClasses groupClasses) {
        startPage();
        List<GroupClasses> list = groupClassesService.selectGroupClassesList(groupClasses);
        return getDataTable(list);
    }

    @ApiOperation("获取班次详细信息")
    @ApiOperationSupport(order = 3)
    @GetMapping("/get/{classesId}")
    public AjaxResult<GroupClasses> getInfo(@PathVariable("classesId") Long classesId) {
        return AjaxResult.success(groupClassesService.selectGroupClassesById(classesId));
    }

    @ApiOperation("新增班次")
    @ApiOperationSupport(order = 4)
    @Log(title = "班次", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody GroupClasses groupClasses) {
        return toAjax(groupClassesService.insertGroupClasses(groupClasses));
    }

    @ApiOperation("修改班次")
    @ApiOperationSupport(order = 5)
    @Log(title = "班次", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody GroupClasses groupClasses) {
        return toAjax(groupClassesService.updateGroupClasses(groupClasses));
    }

    @ApiOperation("删除班次")
    @ApiOperationSupport(order = 6)
    @Log(title = "班次", businessType = BusinessType.DELETE)
	@PostMapping("/remove/{classesIds}")
    public AjaxResult remove(@PathVariable Long[] classesIds) {
        return toAjax(groupClassesService.deleteGroupClassesByIds(classesIds));
    }
}
